package com.ruoyi.web.controller.train;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.domain.SysUserNotice;
import com.ruoyi.system.service.ISysUserNoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户通知记录Controller
 *
 * @author dp
 * @date 2023-12-05
 */
@Api(tags = "用户通知记录")
@RestController
@RequestMapping("/user/notice")
public class SysUserNoticeController extends BaseController {
    @Autowired
    private ISysUserNoticeService sysUserNoticeService;
    @Autowired
    TokenService tokenService;

    /**
     * 查询用户通知记录列表
     */
    @ApiOperation(value = "查询用户通知记录列表", notes = "查询用户通知记录列表", tags = {"用户通知记录"})
    //@PreAuthorize("@ss.hasPermi('system:NOTICE:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysUserNotice sysUserNotice) {
        startPage();
        List<SysUserNotice> list = sysUserNoticeService.selectSysUserNoticeList(sysUserNotice);
        return getDataTable(list);
    }

    /**
     * 导出用户通知记录列表
     */
    @ApiOperation(value = "导出用户通知记录列表", notes = "导出用户通知记录列表", tags = {"用户通知记录"})
    //@PreAuthorize("@ss.hasPermi('system:NOTICE:export')")
    @Log(title = "用户通知记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysUserNotice sysUserNotice) {
        List<SysUserNotice> list = sysUserNoticeService.selectSysUserNoticeList(sysUserNotice);
        ExcelUtil<SysUserNotice> util = new ExcelUtil<SysUserNotice>(SysUserNotice.class);
        util.exportExcel(response, list, "用户通知记录数据");
    }

    /**
     * 获取用户通知记录详细信息
     */
    @ApiOperation(value = "获取用户通知记录详细信息", notes = "获取用户通知记录详细信息", tags = {"用户通知记录"})
    //@PreAuthorize("@ss.hasPermi('system:NOTICE:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId) {
        return success(sysUserNoticeService.selectSysUserNoticeByUserId(userId));
    }

    /**
     * 新增用户通知记录
     */
    @ApiOperation(value = "新增用户通知记录", notes = "新增用户通知记录", tags = {"用户通知记录"})
    //@PreAuthorize("@ss.hasPermi('system:NOTICE:add')")
    @Log(title = "用户通知记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysUserNotice sysUserNotice) {
        return toAjax(sysUserNoticeService.insertSysUserNotice(sysUserNotice));
    }

    /**
     * 修改用户通知记录
     */
    @ApiOperation(value = "修改用户通知记录", notes = "修改用户通知记录", tags = {"用户通知记录"})
    //@PreAuthorize("@ss.hasPermi('system:NOTICE:edit')")
    @Log(title = "用户通知记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysUserNotice sysUserNotice) {
        return toAjax(sysUserNoticeService.updateSysUserNotice(sysUserNotice));
    }

    /**
     * 删除用户通知记录
     */
    @ApiOperation(value = "删除用户通知记录", notes = "删除用户通知记录", tags = {"用户通知记录"})
    //@PreAuthorize("@ss.hasPermi('system:NOTICE:remove')")
    @Log(title = "用户通知记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds) {
        return toAjax(sysUserNoticeService.deleteSysUserNoticeByUserIds(userIds));
    }

}
